function flattenArray(arr) {
  let result = [];
  for (let i = 0; i < arr.length; i++) {
    const current = arr[i];
    if (Array.isArray(current)) {
      // 递归处理嵌套数组
      result.push(...flattenArray(current));
    } else {
      // 非数组元素直接加入结果
      result.push(current);
    }
  }
  return result;
}
// 测试
const nestedArray = [1, [2, [3, 4], 5], 6];
console.log(flattenArray(nestedArray))